#ifndef MONITOR_COMMAND_IN_H_
#define MONITOR_COMMAND_IN_H_
#include "command.h"
#include "ctType.h"
#include <sys/types.h>
#pragma pack(1)

namespace Cmd
{
        namespace Monitor
        {
                //  cmd declaration
                enum
                {
                        CMDIN_LOGIN             = 0x0050,       // 登录MonitorServer验证指令
                        CMDIN_PUSH              = 0x0051,
                        CMDIN_PULL              = 0x0052,
                        CMDIN_CTRL_old          = 0x0053,
                        CMDIN_CONFIG            = 0x0054,
                        CMDIN_HISTORY_old       = 0x0055,
                        CMDIN_REALTIME_DATA     = 0x0056,
                        CMDIN_SYSTEM            = 0x0057,
                        CMDIN_DAEMON            = 0x0058,
                        CMDIN_DUMMY_old         = 0x0059,
                        CMDIN_SEARCH_old        = 0x005A,
                        CMDIN_FORWARD           = 0x005B,
                };
                enum
                { //CMDIN_LOGIN
                        SCMDIN_LOGIN                            = 0x0001,       // 请求登录MonitorServer
                        SCMDIN_LOGIN_RESPONCE                   = 0x0002,	// 登录MointorServer返回
                };
                enum
                { //CMDIN_PUSH
                        SCMDIN_PUSH_SERVERLIST                  = 0x0001,       // super-->monitor
                        SCMDIN_PUSH_SERVERSTART                 = 0x0002,
                        SCMDIN_PUSH_SERVERSTOP                  = 0x0003,
                };
                enum
                {
                        SCMDIN_PULL_USERPOS                     = 0x0001,
                        SCMDIN_PULL_RES_USERPOS                 = 0x0002,
                        SCMDIN_PULL_SERVERLIST_old              = 0x0003,
                        SCMDIN_PULL_RES_SERVERLIST_old          = 0x0004,
                };
                enum
                {
                        SCMDIN_CFG_IM_QUERYSERVERLIST_old       = 0x0001,
                        SCMDIN_CFG_IM_ADDSERVER_old             = 0x0002,
                        SCMDIN_CFG_IM_DELSERVER_old             = 0x0003,
                        SCMDIN_CFG_IM_EDITSERVER_old            = 0x0004,
                        SCMDIN_CFG_IM_RES_QUERYSERVERLIST_old   = 0x0005,
                        SCMDIN_CFG_IM_RES_ADDSERVER_old         = 0x0006,
                        SCMDIN_CFG_IM_RES_DELSERVER_old         = 0x0007,
                        SCMDIN_CFG_IM_RES_EDITSERVER_old        = 0x0008,
                        SCMDIN_CFG_ROOM_QUERYSERVERLIST_old     = 0x0009,
                        SCMDIN_CFG_ROOM_ADDSERVER_old           = 0x000A,
                        SCMDIN_CFG_ROOM_DELSERVER_old           = 0x000B,
                        SCMDIN_CFG_ROOM_EDITSERVER_old          = 0x000C,
                        SCMDIN_CFG_ROOM_RES_QUERYSERVERLIST_old = 0x000D,
                        SCMDIN_CFG_ROOM_RES_ADDSERVER_old       = 0x000E,
                        SCMDIN_CFG_ROOM_RES_DELSERVER_old       = 0x000F,
                        SCMDIN_CFG_ROOM_RES_EDITSERVER_old      = 0x0010,
                        SCMDIN_CFG_ROOM_NOTIFY_MANAGER_old      = 0x0011,
                        SCMDIN_CFG_ROOM_NOTIFY_CHANGE_old       = 0x0012,
                        SCMDIN_CFG_ROOM_DEPLOY_TO_SERVER_REQ    = 0x0013,
                        SCMDIN_CFG_ROOM_DEPLOY_TO_SERVER_RES    = 0x0014,
                };
                enum
                {
                        SCMDIN_REAL_REQ_QUERYONLINE_old         = 0x0001,
                        SCMDIN_REAL_RES_QUERYONLINE_old         = 0x0002,
                        SCMDIN_REAL_REQ_ROOMLOAD_old            = 0x0003,
                        SCMDIN_REAL_RES_ROOMLOAD_old            = 0x0004,
                        SCMDIN_REAL_ROOMSERVER_LOAD_REQ         = 0x0005,
                        SCMDIN_REAL_SESSIONSERVER_LOAD_REQ      = 0x0006,
                        SCMDIN_REAL_GATEWAYSERVER_LOAD_REQ      = 0x0007,
                        SCMDIN_REAL_ROOMMEDIASERVER_LOAD_REQ    = 0x0008,
                        SCMDIN_REAL_ROOMMEDIASERVER_LOAD_RES_old        = 0x0009,
                };
                enum
                {
                        SCMDIN_SYS_CPULOAD                      = 0x0001,
                        SCMDIN_SYS_NETLOAD                      = 0x0002,
                        SCMDIN_SYS_MEMLOAD                      = 0x0003,
                        SCMDIN_SYS_PROCESS                      = 0x0004,
                        SCMDIN_SYS_PROC_CPUS_old                = 0x0005,
                        SCMDIN_SYS_PROC_MEMS_old                = 0x0006,
                        SCMDIN_SYS_PROC_STAT                    = 0x0007,
                };
                enum
                {
                        SCMDIN_DAEMON_LOGIN                     = 0x0001,
                        SCMDIN_DAEMON_LOGIN_RESPONCE            = 0x0002,
                };
                enum
                {
                        SCMDIN_FORWARD_USERCMD_TO_SERVER_BY_TYPE        = 0x0001,
                        SCMDIN_FORWARD_USERCMD_TO_ROOMSERVER_YB_ROOMID  = 0x0002,
                        SCMDIN_FORWARD_USERCMD_TO_MONITOR               = 0x0003,
                        SCMDIN_FORWARD_USERCMD_TO_ROOMSUPERSERVER       = 0x0004,
                        SCMDIN_FORWARD_USERCMD_TO_SUPERSERVER           = 0x0005,
                };

                //	cmd definition
                struct stLoginCmd: t_NullCmd
                {
                        stLoginCmd()
                                : t_NullCmd( CMDIN_LOGIN, SCMDIN_LOGIN )
                        {
                                dest_type_ = MONITORSERVER;
                                server_type_ = 0;
                                server_id_ = 0;
                        }
                        WORD dest_type_;
                        WORD server_type_;
                        DWORD server_id_;
                };
                struct stLoginResponce: t_NullCmd
                {
                        stLoginResponce()
                                : t_NullCmd( CMDIN_LOGIN, SCMDIN_LOGIN_RESPONCE )
                        {
                        }
                };

                struct stMonitorBase: t_NullCmd
                {
                        stMonitorBase( WORD cmd, WORD subcmd )
                                : t_NullCmd( cmd, subcmd )
                        {
                                cid = 0;
                        }

                        DWORD cid;

                };
                struct stDaemonBase: t_NullCmd
                {
                        stDaemonBase( WORD cmd, WORD subcmd )
                                : t_NullCmd( cmd, subcmd )
                        {
                                bzero( server_ip, sizeof( server_ip ) );
                        }

                        char server_ip[MAX_IP_LENGTH + 1];
                };

                struct stMonitorRoomServerLoadReq:
                        stMonitorBase
                {
                        stMonitorRoomServerLoadReq()
                                : stMonitorBase( CMDIN_REALTIME_DATA, SCMDIN_REAL_ROOMSERVER_LOAD_REQ )
                        {
                        }
                };

                struct stMonitorMediaServerLoadReq:
                        stMonitorBase
                {
                        stMonitorMediaServerLoadReq()
                                : stMonitorBase( CMDIN_REALTIME_DATA, SCMDIN_REAL_ROOMMEDIASERVER_LOAD_REQ )
                        {
                        }
                };

                struct stMonitorSessionServerLoadReq:
                        stMonitorBase
                {
                        stMonitorSessionServerLoadReq()
                                : stMonitorBase( CMDIN_REALTIME_DATA, SCMDIN_REAL_SESSIONSERVER_LOAD_REQ )
                        {
                        }
                };

                struct stMonitorGatewayServerLoadReq:
                        stMonitorBase
                {
                        stMonitorGatewayServerLoadReq()
                                : stMonitorBase( CMDIN_REALTIME_DATA, SCMDIN_REAL_GATEWAYSERVER_LOAD_REQ )
                        {
                        }
                };

                struct stPushServerList: stMonitorBase
                {
                        stPushServerList()
                                : stMonitorBase( CMDIN_PUSH, SCMDIN_PUSH_SERVERLIST )
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct stRUL
                        {
                                WORD servertype;
                                WORD serverid;
                                WORD port;
                                BYTE server_ip[MAX_IP_LENGTH + 1];
                                BYTE server_name[MAX_NAME_SIZE + 1];

                        } list_[0];
                        DWORD getSize()
                        {
                                return sizeof( *this ) + size_ * sizeof( list_[0] );
                        }

                };
                struct st_PushServerStart: stMonitorBase
                {
                        st_PushServerStart()
                                : stMonitorBase( CMDIN_PUSH, SCMDIN_PUSH_SERVERSTART )
                        {
                        }
                        struct stRUL
                        {
                                stRUL()
                                {
                                        bzero( this, sizeof( *this ) );
                                }
                                WORD servertype;
                                WORD serverid;
                                WORD port;
                                BYTE server_ip[MAX_IP_LENGTH + 1];
                                BYTE server_name[MAX_NAME_SIZE + 1];

                        } server;
                };
                struct st_PushServerStop: stMonitorBase
                {
                        st_PushServerStop()
                                : stMonitorBase( CMDIN_PUSH, SCMDIN_PUSH_SERVERSTOP )
                        {
                                serverid = 0;
                        }
                        WORD serverid;
                };

                struct st_PullUserPos: stMonitorBase
                {
                        st_PullUserPos()
                                : stMonitorBase( CMDIN_PULL, SCMDIN_PULL_USERPOS )
                        {
                                userid = 0;
                        }
                        DWORD userid; //如果userid=0，使用username查询
                        BYTE username[MAX_NAME_SIZE + 1];
                };
                struct st_PullResUserPos: stMonitorBase
                {
                        st_PullResUserPos()
                                : stMonitorBase( CMDIN_PULL, SCMDIN_PULL_RES_USERPOS )
                        {
                                userid = 0;
                                gateway_server_id = 0;
                                session_server_id = 0;
                        }
                        DWORD userid;
                        DWORD gateway_server_id;
                        DWORD session_server_id;
                };

                struct st_ConfigRoomDeployReq: stMonitorBase
                {
                        st_ConfigRoomDeployReq()
                                : stMonitorBase( CMDIN_CONFIG, SCMDIN_CFG_ROOM_DEPLOY_TO_SERVER_REQ )
                        {
                                serverid_from_ = 0;
                                serverid_to_ = 0;
                                roomid_ = 0;
                        }
                        DWORD serverid_from_;
                        DWORD serverid_to_;
                        DWORD roomid_;
                };

                struct st_ConfigRoomDeployRes: stMonitorBase
                {
                        st_ConfigRoomDeployRes()
                                : stMonitorBase( CMDIN_CONFIG, SCMDIN_CFG_ROOM_DEPLOY_TO_SERVER_RES )
                        {
                                serverid_from_ = 0;
                                serverid_to_ = 0;
                                roomid_ = 0;
                                ret_ = 0;
                        }
                        DWORD serverid_from_;
                        DWORD serverid_to_;
                        DWORD roomid_;
                        BYTE ret_;  //0-fail, 1-success, 2-deploying
                };

                struct stPushCPUload: stDaemonBase
                {
                        stPushCPUload()
                                : stDaemonBase( CMDIN_SYSTEM, SCMDIN_SYS_CPULOAD )
                        {
                        }
                        struct stRUL
                        {
                                float user;
                                float system;
                                float nice;
                                float idle;

                        } data;
                };

                struct stPushMemload: stDaemonBase
                {
                        stPushMemload()
                                : stDaemonBase( CMDIN_SYSTEM, SCMDIN_SYS_MEMLOAD )
                        {
                        }
                        struct stRUL
                        {
                                DWORD used;
                                DWORD free;
                                DWORD total;

                        } data;
                };

                struct stPushNetload: stDaemonBase
                {
                        stPushNetload()
                                : stDaemonBase( CMDIN_SYSTEM, SCMDIN_SYS_NETLOAD )
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct stRUL
                        {
                                char ethname[8];
                                char ip[MAX_IP_LENGTH + 1];
                                DWORD recvBytes;
                                DWORD recvPackets;
                                DWORD sendBytes;
                                DWORD sendPackets;

                        } list_[0];
                        DWORD getSize()
                        {
                                return sizeof( *this ) + size_ * sizeof( list_[0] );
                        }
                };

                struct stPushProcStat: stDaemonBase
                {
                        stPushProcStat()
                                : stDaemonBase( CMDIN_SYSTEM, SCMDIN_SYS_PROC_STAT )
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct stRUL
                        {
                                int procID;
                                int serverID;
                                char procName[33];
                                float cpu_user;
                                float cpu_system;
                                float cpu_idle;
                                DWORD mem_vm;
                                DWORD mem_phy;

                        } list_[0];
                        DWORD getSize()
                        {
                                return sizeof( *this ) + size_ * sizeof( list_[0] );
                        }
                };
                struct stResProcessList: stDaemonBase
                {
                        stResProcessList()
                                : stDaemonBase( CMDIN_SYSTEM, SCMDIN_SYS_PROCESS )
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct stRUL
                        {
                                DWORD pid;
                                DWORD pri;
                                DWORD systemjifs;
                                DWORD userjifs;
                                DWORD rss;	// in pages ...
                                short cpuid;
                                char state;

                        } list_[0];
                        DWORD getSize()
                        {
                                return sizeof( *this ) + size_ * sizeof( list_[0] );
                        }

                };

                struct stDaemonLoginCmd: t_NullCmd
                {
                        stDaemonLoginCmd()
                                : t_NullCmd( CMDIN_DAEMON, SCMDIN_DAEMON_LOGIN )
                        {
                                bzero( server_ip, sizeof( server_ip ) );
                                server_id_ = 0;
                        }
                        char server_ip[MAX_IP_LENGTH + 1];
                        DWORD server_id_;
                };
                struct stDaemonLoginResponce: t_NullCmd
                {
                        stDaemonLoginResponce()
                                : t_NullCmd( CMDIN_DAEMON, SCMDIN_DAEMON_LOGIN_RESPONCE )
                        {
                        }
                };

                struct st_ForwardUserCmdToServerByType: stMonitorBase
                {
                        st_ForwardUserCmdToServerByType()
                                : stMonitorBase( CMDIN_FORWARD, SCMDIN_FORWARD_USERCMD_TO_SERVER_BY_TYPE )
                        {
                                monitor_id_ = 0;
                                server_type_ = 0;
                                size_ = 0;
                        }

                        const WORD getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        WORD monitor_id_;
                        WORD server_type_;
                        WORD size_;
                        char data_[0];
                };

                struct st_ForwardUserCmdToRoomServerByRoomId: stMonitorBase
                {
                        st_ForwardUserCmdToRoomServerByRoomId()
                                : stMonitorBase( CMDIN_FORWARD, SCMDIN_FORWARD_USERCMD_TO_ROOMSERVER_YB_ROOMID )
                        {
                                monitor_id_ = 0;
                                room_id_ = 0;
                                size_ = 0;
                        }

                        const WORD getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        WORD monitor_id_;
                        DWORD room_id_;
                        WORD size_;
                        char data_[0];
                };

                struct st_ForwardUserCmdToMonitor: stMonitorBase
                {
                        st_ForwardUserCmdToMonitor()
                                : stMonitorBase( CMDIN_FORWARD, SCMDIN_FORWARD_USERCMD_TO_MONITOR )
                        {
                                monitor_id_ = 0;
                                size_ = 0;
                        }

                        const WORD getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        WORD monitor_id_;
                        WORD size_;
                        char data_[0];
                };

                struct st_ForwardUserCmdToRoomSuperServer: stMonitorBase
                {
                        st_ForwardUserCmdToRoomSuperServer()
                                : stMonitorBase( CMDIN_FORWARD, SCMDIN_FORWARD_USERCMD_TO_ROOMSUPERSERVER )
                        {
                                monitor_id_ = 0;
                                size_ = 0;
                        }

                        const WORD getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        WORD monitor_id_;
                        WORD size_;
                        char data_[0];
                };
                struct st_ForwardUserCmdToSuperServer: stMonitorBase
                {
                        st_ForwardUserCmdToSuperServer()
                                : stMonitorBase( CMDIN_FORWARD, SCMDIN_FORWARD_USERCMD_TO_SUPERSERVER )
                        {
                                monitor_id_ = 0;
                                size_ = 0;
                        }

                        const WORD getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        WORD monitor_id_;
                        WORD size_;
                        char data_[0];
                };
        };//namespace Monitor
};//namespace Cmd

#pragma pack() //pack(1)
#endif //MONITOR_COMMAND_IN_H_
